angular.module('app.controllers', [])
  
.controller('side-menu21Ctrl', ['$scope', '$stateParams','getUserAccountService', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope, $stateParams,getUserAccountService) {
}])
   
.controller('page2Ctrl', ['$scope','$timeout','$stateParams','$http','getSchoolNameService',// The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope,$timeout, $stateParams,$http,getSchoolNameService) {
	 $scope.page2DoRefresh = function() {
    Math.random()*8
		var num = Math.random()*8 + 1;
		num = parseInt(num, 10);
		num1 = num+1;
		num2 = num+2;
		num3 = num+3
		var page2Http = "http://localhost:8080/schoolName/"+num;
		var page2Http1 = "http://localhost:8080/schoolName/"+num1;
		var page2Http2 = "http://localhost:8080/schoolName/"+num2;
		var page2Http3 = "http://localhost:8080/schoolName/"+num3;
		$http.get(page2Http).then(
		function(res){
			$scope.page2FirstSchool = res.data;
		},function(){
			alert("读取失败，请刷新重试");
		});
		$http.get(page2Http1).then(
		function(res){
			$scope.page2SecondSchool = res.data;
		},function(){
			alert("读取失败，请刷新重试");
		});
		$http.get(page2Http2).then(
		function(res){
			$scope.page2ThirdSchool = res.data;
		},function(){
			alert("读取失败，请刷新重试");
		});
		$http.get(page2Http3).then(
		function(res){
			$scope.page2FourthSchool = res.data;
		},function(){
			alert("读取失败，请刷新重试");
		})
    .finally(function() {
      $scope.$broadcast('scroll.refreshComplete');
    });
  };
	//获取搜索框的值传给页面7
	$scope.getPage2SchoolName = function(schoolName){
		getSchoolNameService.setSchoolName(schoolName);
	}
	//	定义三种活动类型
	$scope.page2ALiteraryStyle = "文体";
	$scope.page2SuburbanTour = "郊外游";
	$scope.page2SocialWelfare = "社会公益";
	//根据三种活动类型获取三种热门活动
	
//	$http.get("http://localhost:8080/hotActivity/activityType/文体").then(
//		function(res){
//			$scope.page2ALiteraryStyleActivity = res.data;
//			console.log($scope.page2ALiteraryStyleActivity)
//		},function(){
//			alert("读取失败，请刷新重试");
//		});
//$http.get("http://localhost:8080/hotActivity/activityType/郊外游").then(function (res) {
//			$scope.page2SuburbanTourActivity=res.data;
//			console.log($scope.page2SuburbanTourActivity)
//  	}, function () {
//      alert("读取失败，请刷新重试");
//});
//$http.get("http://localhost:8080/hotActivity/activityType/社会公益").then(function (res) {
//			$scope.page2SocialWelfare=res.data;
//			console.log($scope.page2SocialWelfare)
//  	}, function () {
//      alert("读取失败，请刷新重试");
//});
		//生成随机数获取4所热门大学
		Math.random()*8
		var num = Math.random()*8 + 1;
		num = parseInt(num, 10);
		num1 = num+1;
		num2 = num+2;
		num3 = num+3
		var page2Http = "http://localhost:8080/schoolName/"+num;
		var page2Http1 = "http://localhost:8080/schoolName/"+num1;
		var page2Http2 = "http://localhost:8080/schoolName/"+num2;
		var page2Http3 = "http://localhost:8080/schoolName/"+num3;
		$http.get(page2Http).then(
		function(res){
			$scope.page2FirstSchool = res.data;
		},function(){
			alert("读取失败，请刷新重试");
		});
		$http.get(page2Http1).then(
		function(res){
			$scope.page2SecondSchool = res.data;
		},function(){
			alert("读取失败，请刷新重试");
		});
		$http.get(page2Http2).then(
		function(res){
			$scope.page2ThirdSchool = res.data;
		},function(){
			alert("读取失败，请刷新重试");
		});
		$http.get(page2Http3).then(
		function(res){
			$scope.page2FourthSchool = res.data;
		},function(){
			alert("读取失败，请刷新重试");
		});
		//向其他页面共享数据
		$scope.page2SendSchoolName = function(schoolName){
			getSchoolNameService.setSchoolName(schoolName);
		}
}])
   
.controller('page3Ctrl', ['$scope','$timeout','$stateParams','$http','$state','getActivityNameService',// The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope,$timeout,$stateParams,$http,$state,getActivityNameService) {
//	定义三种活动类型
	$scope.page3ALiteraryStyle = "文体";
	$scope.page3SuburbanTour = "郊外游";
	$scope.page3SocialWelfare = "社会公益";
	
//	获取所有活动
	$http.get('http://localhost:8080/activities').then(function (res) {
			$scope.page3ActivityArr=res.data;
    	}, function () {
        alert("读取失败，请刷新重试");
  });
	
//	根据活动类型获取活动内容
	$scope.page3GetActivityByType = function(activityType){
		var http = "http://localhost:8080/activityDetails/activityType/"+activityType
		$http.get(http).then(
			function(res){
				$scope.page3ActivityArr = res.data;
			},function(){
				alert("读取失败，请刷新重试");
			});
	}

//		获取活动的名称并传递给活动详情页面
	$scope.page3GetActivityName = function(activityName){
	
		getActivityNameService.setName(activityName);
	}
//下拉刷新页面
	$scope.page3DoRefresh = function() {
    $http.get('http://localhost:8080/activities').then(function (res) {
			$scope.page3ActivityArr=res.data;
    	}, function () {
        alert("读取失败，请刷新重试");
  	})
    .finally(function() {
      $scope.$broadcast('scroll.refreshComplete');
    });
  };
//上拉加载
  $scope.page3State = true;
  $scope.count = 3;
  $scope.loadMore = function() {
  	
  	$http.get('http://localhost:8080/activities').then(function (res) {
			$scope.page3ActivityArr=res.data;
    	},function () {
        alert("读取失败，请刷新重试");
  	})
  	console.log(1);
  	while($scope.page3ActivityArr.length>$scope.count)
  	{
  		$scope.count =$scope.count+3 ;
  	}
  	$scope.page3State = false;
  };
}])
   
.controller('page4Ctrl', ['$scope', '$stateParams','$http','getQuestionService', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope, $stateParams,$http,getQuestionService) {
	//获取交流的信息
	$http.get("http://localhost:8080/questions").then(function(res){
			$scope.page4QuestionArr = res.data;
		},function(){
			alert("读取失败，请刷新重试");
	})
	//共享问题
	$scope.page4SendQuestion = function(content){
		getQuestionService.setQuestionContent(content);
	}
	//	刷新页面
	$scope.page4DoRefresh = function() {
    $http.get("http://localhost:8080/questions").then(function(res){
			$scope.page4QuestionArr = res.data;
		},function(){
			alert("读取失败，请刷新重试");
	})
  .finally(function() {
      $scope.$broadcast('scroll.refreshComplete');
  	});
  };
}])
      
.controller('page5Ctrl', ['$scope', '$stateParams','$http','getUserAccountService', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope, $stateParams,$http,getUserAccountService) {
	$scope.person = {
		userAccount:null,
		userPassword:null
	}
	$scope.page5Log = function(page5Account,page5Password){
		getUserAccountService.setAccount(page5Account);
	
		var page5Http = "http://localhost:8080/users/allUserInfo/"+page5Account;
		$http.get(page5Http).then(function(res){
			$scope.page5UserInfo = res.data;
			console.log($scope.page5UserInfo);
			if($scope.page5UserInfo.userPasswod!=page5Password){
				alert("你的密码错误，登录失败！")
			}
		},function(){
			alert("你的账户出错！");
		})
	}
}])
   
.controller('page6Ctrl', ['$scope', '$stateParams','$http', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope, $stateParams,$http) {
	$scope.page6User = {
			userAccount:null,
			userPassword:null,
			userName:null,
			userContract:null,
			userEmail:null
	}
	$scope.page6LogIn = function(){
		$http({
      method: "post",
      url: "http://localhost:8080/logIn",
      data: $scope.page6User
      }).success(function (date){
            // handle success
         	})
	}
}])
   
.controller('page7Ctrl', ['$scope', '$stateParams','$http','getSchoolNameService', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope, $stateParams,$http,getSchoolNameService) {
	//通过首页输入框的数据获取活动内容
	$scope.page7Temp = getSchoolNameService.getSchoolName();
	var page7Http = "http://localhost:8080/schoolActivity/schoolName/"+$scope.page7Temp
	$http.get(page7Http).then(function(res){
			$scope.page7SchoolActivityList = res.data;
			console.log($scope.page7SchoolActivityList);
		},function(){
			alert("读取失败，请刷新重试");
		})
}])
   
.controller('page8Ctrl', ['$scope', '$stateParams','$http','$state','getActivityNameService',// The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope,$stateParams,$http,$state,getActivityNameService) {
//	获取活动的详细内容
    $scope.page8Temp = getActivityNameService.getName();
		var http = "http://localhost:8080/activityDetails/activity/"+$scope.page8Temp
		$http.get(http).then(function(res){
			$scope.page8ActivityDet = res.data;
		},function(){
			alert("读取失败，请刷新重试");
		})
		//	刷新页面
	$scope.page8DoRefresh = function() {
    $scope.page8Temp = getActivityNameService.getName();
		var http = "http://localhost:8080/activityDetails/activity/"+$scope.page8Temp
		$http.get(http).then(function(res){
			$scope.page8ActivityDet = res.data;
		},function(){
			alert("读取失败，请刷新重试");
		}).finally(function() {
      	$scope.$broadcast('scroll.refreshComplete');
  		});
  };
}])
   
.controller('page9Ctrl', ['$scope', '$stateParams','$http','getActivityNameService', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope, $stateParams,$http,getActivityNameService) {
//	定义更新对象
	$scope.page9Attendance = {
		activityName:getActivityNameService.getName(),
		attendance:null
	}
//	获取需要更新的数据并上传更新内容
	$scope.page9GetAttendance = function(){
		var http = "http://localhost:8080/attendance/activityName/"+getActivityNameService.getName()
		$http.get(http).then(function(res){
			$scope.page9ActivityDet = res.data;
			$scope.page9Attendance.attendance = $scope.page9ActivityDet.attendance+1;
			$http({
      method: "post",
      url: "http://localhost:8080/updateAttendance",
      data: $scope.page9Attendance
      }).success(function (date){
            // handle success
         })
		},function(){
			alert("读取失败，请刷新重试");
		})	
	}
	

}])
   
.controller('page10Ctrl', ['$scope','$state','$stateParams','$http','getUserAccountService',// The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope,$state,$stateParams,$http,getUserAccountService) {
//	定义一个person对象
	$scope.page10Person = {
				userAccount:getUserAccountService.getAccount(),
				userName:null,
				userAge:null,
				userSex:null,
				userContract:null,
				userEmail:null
			};
//		得到用户信息
//	$scope.accout = ;
	var http = 'http://localhost:8080/users/userAccount/'+$scope.page10Person.userAccount;
	$http.get(http).then(function(res){
			$scope.page10UserInfo = res.data;
			$scope.page10Person.userName=$scope.page10UserInfo.userName;
			$scope.page10Person.userAge=$scope.page10UserInfo.userAge;
			$scope.page10Person.userSex=$scope.page10UserInfo.userSex;
			$scope.page10Person.userContract=$scope.page10UserInfo.userContract;
			$scope.page10Person.userEmail=$scope.page10UserInfo.userEmail;
		},function(){
			alert("读取失败，请刷新重试");
		});
//			更新用户信息
	$scope.page10UpdatePerson = function(){
    $http({
      method: "post",
      url: "http://localhost:8080/userAccount",
      data: $scope.page10Person
      }).success(function (date){
            // handle success
          })
  };
//返回首页
  $scope.page10To = function(){
  	$state.go("tabsController.page2",{}, {reload: true})
  }
}])
   
.controller('page11Ctrl', ['$scope','$state','$stateParams','$http','getUserAccountService', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope,$state,$stateParams,$http,getUserAccountService) {
//	获取数据
	var http = 'http://localhost:8080/personActivity/userAccount/'+getUserAccountService.getAccount();
	$http.get(http).then(function(res){
			$scope.page11PersonActivity=res.data;
			console.log($scope.page11PersonActivity)
		},function(){
			alert("读取失败，请刷新重试");
		});
//	跳转到首页
	$scope.page11To = function(){
  	$state.go("tabsController.page2",{}, {reload: true})
  }
}])
   
.controller('page12Ctrl', ['$scope','$state','$stateParams','$http', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope,$state,$stateParams,$http) {
	
	$scope.page12Activity = {
		activitySponsor:null,
		activityName:null,
		activityTime:null,
		activityAddress:null,
		activityType:'文体',
		activityContent:null,
		activityAttendance:0,
		activityState:"正在进行"
	};
	$scope.page12AddActivity = function(){
		$http({
      method: "post",
      url: "http://localhost:8080/activity",
      data: $scope.page12Activity
    }).success(function (date){
        // handle success
    })
	}
	
	$scope.page12To = function(){
  	$state.go("tabsController.page2",{}, {reload: true})
  }
}])
   
.controller('page13Ctrl', ['$scope', '$stateParams','$http','getQuestionService', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope, $stateParams,$http,getQuestionService) {
	$scope.page13Temp = getQuestionService.getQuestionContent();
	var page13Http = "http://localhost:8080/review/questionContent/"+$scope.page13Temp
	$http.get(page13Http).then(function(res){
			$scope.page13ReviewArr=res.data;
		},function(){
			alert("读取失败，请刷新重试");
		});
	//	刷新页面
	$scope.page13DoRefresh = function() {
    $scope.page13Temp = getQuestionService.getQuestionContent();
		var page13Http = "http://localhost:8080/review/questionContent/"+$scope.page13Temp
		$http.get(page13Http).then(function(res){
			$scope.page13ReviewArr=res.data;
		},function(){
			alert("读取失败，请刷新重试");
		}).finally(function() {
      	$scope.$broadcast('scroll.refreshComplete');
  		});
  };
}])
   
.controller('page14Ctrl', ['$scope', '$stateParams','$http','getUserAccountService','getQuestionService', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope, $stateParams,$http,getUserAccountService,getQuestionService) {
	$scope.page14UserAccount = getUserAccountService.getAccount();
	$scope.page14QuestionContent = getQuestionService.getQuestionContent();
	$scope.page14Review = {
		userAccount:$scope.page14UserAccount,
		questionContent:$scope.page14QuestionContent,
		answerContent:null
	}
//	发表评论
	$scope.page14UpdateReview = function(){
    $http({
      method: "post",
      url: "http://localhost:8080/reviewContent",
      data: $scope.page14Review
      }).success(function (date){
            // handle success
      })
  };

}])
 